package main.com;

import java.util.ArrayList;

import android.R.bool;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebChromeClient.CustomViewCallback;

public class MouseActivity extends View {

	private ArrayList<DrawPoint>point = new ArrayList<DrawPoint>();
	
	public void addPoint(DrawPoint p)
	{
		point.add(p);
	}
	
	public MouseActivity(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public boolean onTouchEvent(MotionEvent event)
	{
		DrawPoint p = new DrawPoint((int)event.getX(),(int)event.getY());
		switch(event.getAction())
		{
			case android.view.MotionEvent.ACTION_DOWN:
				p.start=true;
				break;
				
			case android.view.MotionEvent.ACTION_CANCEL:
			Log.d("TouchView", "On touch cacelled");
			break;
		}
		addPoint(p);
		invalidate();
		return true;
	}
	public void onDraw(Canvas c)
	{
		super.onDraw(c);
		Path path= new Path();
		for(int i=0;i<point.size();i++)
		{
			DrawPoint currentPoint=point.get(i);
			if(currentPoint.start==true)
				path.moveTo(currentPoint.p.x, currentPoint.p.y);
			else
				path.lineTo(currentPoint.p.x, currentPoint.p.y);
		}
		Paint paint= new Paint();
		paint.setStyle(Paint.Style.STROKE);
		paint.setStrokeWidth(2);
		paint.setColor(Color.BLACK);
		c.drawPath(path, paint);
	}
	
	private class DrawPoint
	{
		public boolean start=false;
		public Point p;
		DrawPoint(int x,int y)
		{
			p= new Point(x,y);
		}
	}
    
}

